<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	
	//设置当前年份
	Calendar cal = Calendar.getInstance();
	int curYear = cal.get(Calendar.YEAR);
	request.setAttribute("curYear", curYear);
	
	//最近5年
	List yearList = new ArrayList();
	for(int i = curYear; i > curYear-5; i--){
		yearList.add(i);
	}
	request.setAttribute("yearList", yearList);
%>

<!DOCTYPE HTML>
<html>
  <head>
    <%@include file="/common/header.jsp"%>
    <title>年度投诉统计图</title>
    <script type="text/javascript" src="${basePath }js/fusioncharts/fusioncharts.js"></script>
<script type="text/javascript" src="${basePath }js/fusioncharts/themes/fusioncharts.theme.fint.js"></script>
<script type="text/javascript">

	//根据年度获取该年度的投诉数
	function doAnnualStatistic(){
		var year = $("#year option:selected").val();
		if(year == undefined || year == "" || year == null){
			year = "${curYear}";
		}
		$.ajax({
			url: "${basePath}nsfw/complain_getAnnualStatisticData.action",
			data: {"year" : year},
			type: "post",
			dataType: "json",
			success: function(data){
				//根据年度获取该年度的每个月对应的投诉统计数以json格式数据返回
				var revenueChart = new FusionCharts({
					"type" : "line",
					"renderAt" : "chartContainer",
					"width" : "650",
					"height" : "420",
					"dataFormat" : "json",
					"dataSource" : {
						"chart" : {
							"caption" : year + "年年度投诉数统计图",
							"xAxisName" : "月  份",
							"yAxisName" : "投  诉  数",
							"theme" : "fint"
						},
						"data" : data.statisticData
					}

				});
				revenueChart.render();
			},
			error : function(){alert("获取年度投诉数失败！");}
		});
	}
	//初始页面时加载当前年份投诉数
	$.ready(doAnnualStatistic());
</script>
  </head>
  
  <body>
  	<div style="text-align:center;width:100%;">
  		<br>
	    <s:select id="year" list="#request.yearList" onchange="doAnnualStatistic()"></s:select>
	    <br>
	    <div id="chartContainer"></div>
  	</div>
  </body>
</html>
